/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufrn.adurn.architecture.dao;

import br.ufrn.adurn.domain.Pensionista;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Date;
import java.util.List;

/**
 *
 * @author Administrador
 */
public class PensionistaDAO {

    private Connection connection;

    public PensionistaDAO() {
        this.connection = new ConnectionFactory().getConnection();
    }

    public void adiciona(Pensionista pensionista) {
        String sql = "INSERT INTO pensionistas (nome, cpf, data_nasc, logradouro, complemento,"
                + " bairro, cep, cidade, uf, email, newsletter, tel1, tel2, end_valido, mala_direta, observacoes, dataAtualizacao, usuario) "
                + "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

        try {
            PreparedStatement stmt = connection.prepareStatement(sql);
            stmt.setString(1, pensionista.getNome());
            stmt.setString(2, pensionista.getCpf());
            stmt.setDate(3, new Date(pensionista.getDataNasc().getTimeInMillis()));
            stmt.setString(4, pensionista.getLogradouro());
            stmt.setString(5, pensionista.getComplemento());
            stmt.setString(6, pensionista.getBairro());
            stmt.setString(7, pensionista.getCep());
            stmt.setString(8, pensionista.getCidade());
            stmt.setString(9, pensionista.getUf());
            stmt.setString(10, pensionista.getEmail());
            stmt.setBoolean(11, pensionista.isNewsletter());
            stmt.setString(12, pensionista.getTel1());
            stmt.setString(13, pensionista.getTel2());
            stmt.setBoolean(14, pensionista.isEnderecoValido());
            stmt.setBoolean(15, pensionista.isMalaDireta());
            stmt.setDate(16, new Date(pensionista.getDataAtualizacao().getTimeInMillis()));
            stmt.setString(17, pensionista.getUsuario());

            stmt.execute();
            stmt.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        System.out.println("Pensionista " + pensionista.getNome() + " adicionado com sucesso");
    }

    public void remove(Pensionista pensionista) {
//        try {
//            PreparedStatement stmt = connection.prepareStatement("delete from pensionistas where id=?");
//            stmt.setLong(1, pensionista.getIdProfessor());
//            stmt.execute();
//            stmt.close();
//        } catch (SQLException e) {
//            throw new RuntimeException(e);
//        }
    }

    public List<Pensionista> getLista(String idProf) {
        return null;
    }
}
